clear
clear mata
clear matrix

cd ..                                                                          /* Goes back to parent folder */

capture log close
log using "log/results-main.log", replace

mkdir tmp/

*       Patriotism!

*       FIRST VERSION  June	       2, 2022
*       THIS VERSION   June        2, 2022
*       LAST RUN       January     2, 2022

*       AUTHOR              AT
*       LAST REVISOR		

*       Log of revisions:

*       This produces tables and figures in the main text

***************************************************************************************************
****                              PLAN OF THE PROCEDURE                                        ****
****___________________________________________________________________________________________****
****                                                                                           ****
****     I. Tables                                                                             ****
****         Tab 1. Summary statistics                                                         ****
****         Tab 2. New Deal and Patriotism: Basic Patterns                                    ****
****         	  	a. Panel A   						                                       ****
****         	  	b. Panel B   						                                       ****
****         Tab 3. New Deal Support and Patriotism: Individual-Level Results                  ****
****         	  a. Panel D   						                                           ****
****         Tab 4. Identification			                                    			   ****
****         Tab 5. Identification: Individual level			                               ****
****     II. Figures                                                                           ****
****         Fig 1. New Deal Spending and WW II Patriotis			                           ****
****         Fig 2. Geographic Distribution of Main Variables			                       ****
****              	a. War bonds                                              				   ****
****              	b. Volunteers                                                              ****
****              	c. Medals                                                 				   ****
****              	d. New Deal grants                                        			       ****
****              	e. Agricultural support                                   				   ****
****              	f. Droughts                                               				   ****
****         Fig 3. Identification										                       ****
****             	a. Droughts                                            				       ****
****             	b. Committees                                            		     	   ****
****         Fig 4. Pre-New Deal Droughts										               ****
****                a. Droughts and AAA spending overtime                  				       ****
****                b. Patriotism and pre-New Deal droughts                  				   ****
****     III. Erase junk                                                                       ****
****___________________________________________________________________________________________****
***************************************************************************************************

macro def control  			 "ww1_vol_sh ww1_awards_pop10_is lpop30 c30unemp c30urban1 c30farm iYf_T29 MEAN9628 c30men c30black c30jap c30deu c30ita c30vet lc40wage iwarconpro_PC i.stateicpsr"
macro def control_nofe       "ww1_vol_sh ww1_awards_pop10_is lpop30 c30unemp c30urban1 c30farm iYf_T29 MEAN9628 c30men c30black c30jap c30deu c30ita c30vet lc40wage iwarconpro_PC"
macro def controls_asn       "h w bmi C40NONWHITE C40MARRIED noncitizen C40SCHOOL_E  C40SCHOOL_H C40SCHOOL_C i.C40AGE"
macro def controls_asn_noage "h w bmi C40NONWHITE C40MARRIED noncitizen C40SCHOOL_E  C40SCHOOL_H C40SCHOOL_C"

********************************************************************************
****           0. Prepare datasets                                          ****
****           		i. ASN                                      		    ****
******************************************************************************** 

use "data/patriotism-ASN", clear

lab var iAAA_PF_farmer   				 "AAA grants $\times$ farmer"
lab var iAAA_PF_farmhand  				 "AAA grants $\times$ farm-hand"
lab var iSUM3MO_DROUGHT3340_farmer    	 "Summer droughts: 1933-40 $\times$ farmer"
lab var iAGRI_T73_farmer 				 "Tenure in Agri committee: 1933-35 $\times$ farmer"
lab var iSUM3MO_DROUGHT3340_farmhand     "Summer droughts: 1933-40 $\times$ farm-hand"
lab var iAGRI_T73_farmhand  			 "Tenure in Agri committee: 1933-35 $\times$ farm-hand"
lab var farmer							 "Farmer"
lab var farmhand						 "Farm-hand"

save "tmp/asn", replace

********************************************************************************
****           		ii. Main                                      		    ****
********************************************************************************   
use "data\patriotism", clear

lab var lpop30         		"log 1930 population"
lab var c30unemp            "1930 unemployment rate"
lab var c40unemp            "1940 unemployment rate"
lab var lc40wage       		"log 1939 average wage"
lab var c30urban1           "Urban status: 1930"
lab var MEAN9628       		"Mean Democratic vote share: 1898-1928"
lab var c30men         		"1930 share of men"
lab var c30black       		"1930 share of blacks"
lab var c30jap         		"1930 share of Japaneses"
lab var c30deu        	 	"1930 share of Germans"
lab var c30ita         		"1930 share of Italians"
lab var c30vet         		"1930 share of veterans"
lab var invpop_w99     		"Inverse of 1930 population"
lab var c30farm        		"1930 farm share"
lab var iwarbond_1944_PC    "1944 war bond purchases p.c." 
lab var ww2_vol_pop40       "WWII volunteers per 1940 population"
lab var iwarconpro_PC       "WII war contract per capita"
lab var ww1_vol_sh          "WWI volunteering rate"
lab var ww1_vol_pop10       "WWI volunteers per capita"
lab var ww1_awards_pop10_is "WWI awards per capita"
lab var iYf_T29             "1929 farm income"
lab var shown_1930          "1930 share of farm-owners"
lab var iSUM3MO_DROUGHT3340 "Months of drought: 1933-40"
lab var iAGRI_T62           "Tenure agri committee: 1911-13"
lab var iAGRI_T73           "Tenure agri committee: 1933-35"
lab var iHOLC_PH            "HOLC loans"
lab var iinfra_AL           "Public works grants"
lab var iRFC_PC             "RFC loans"
lab var iNDEXP_PC      		"New Deal grants"
lab var iSSA_PB        		"Public Assistance"
lab var iAGRI_PF       		"Agricultural support"
lab var EW_AL          		"Emergency workers"
lab var tye_tfe890_500k_100_l6 "Frontier experience"
lab var ww2_awards_pop40_is "WWII medals per 1940 population"

save "tmp/patriot", replace

do "code-build/01_Shopping_List.do"

***************************************************************************************************
****     I. Tables                                                                             ****
****         Tab 1. Summary statistics                                                         ****
***************************************************************************************************
use "tmp/patriot", replace

preserve
	replace ww2_vol_pop40       = . if servicecommand == 7
	replace ww2_volw_pop40      = . if servicecommand == 7
	replace ww2_awards_pop40_is = . if servicecommand == 7
	
	lab var iwarbond_1944_PC    "1944 war bond purchases p.c. (i.h.s.)"
	lab var ww2_vol_pop40       "WWII volunteers per 1940 population ($\times$100)"
	lab var ww2_awards_pop40_is "WWII medals per 1940 population ($\times$1000, i.h.s.)"
	
	lab var iNDEXP_PC           "New Deal grants per 1930 population (i.h.s.)"
	lab var iAGRI_PF            "AAA grants and FCA loans per 1930 farmers (i.h.s.)"
	lab var iSSA_PB             "Public assistance grants per beneficiary (i.h.s.)"
	lab var EW_AL               "Emergency workers per worker (1938)"
	lab var iinfra_AL           "Public works grants per worker (i.h.s.)"
	lab var iHOLC_PH            "HOLC loans per 1930 home owners (i.h.s.)"
	lab var iRFC_PC             "RFC loans per 1930 population (i.h.s.)"
	
	lab var iSUM3MO_DROUGHT3340 "Number of drought months: 1933-40 (i.h.s.)"
	lab var iAGRI_T73           "Tenure in agricultural committee: 1933-35 (i.h.s.)"
	
	lab var ww1_vol_pop10       "WWI volunteers per 1910 population ($\times$ 100)"
	lab var ww1_vol_sh          "WWI volunteer share"
	lab var ww1_awards_pop10_is "WWI medals per 1910 population ($\times$1000, i.h.s.)"
	
	lab var MEAN9628            "Average vote share for the Democrats: 1898-1928"
	lab var lpop30              "log 1930 population"
	lab var c30urban1           "Urban status: 1930"
	lab var iYf_T29             "1929 farm income"
	lab var c30farm             "1930 farm share"
	lab var shown_1930			"1930 share of farm-owners"
	lab var c30men              "1930 share of men"
	lab var c30black            "1930 share of blacks"
	lab var c30jap              "1930 share of Japaneses"
	lab var c30deu              "1930 share of Germans"
	lab var c30ita              "1930 share of Italians"
	lab var c30vet              "1930 share of veterans"
	
	lab var c30unemp            "1930 unemployment rate"
	lab var c40unemp            "1940 unemployment rate"
	lab var lc40wage            "log 1939 average wage"
	lab var iwarconpro_PC       "WWII war contract per capita (i.h.s.)"
			
	estpost summarize iwarbond_1944_PC ww2_vol_pop40 ww2_awards_pop40_is ///
	iNDEXP_PC iAGRI_PF iSSA_PB EW_AL iinfra_AL iHOLC_PH iRFC_PC ///
	iSUM3MO_DROUGHT3340 iAGRI_T73 ///
	ww1_vol_pop10 ww1_vol_sh ww1_awards_pop10_is ///
	MEAN9628 lpop30 c30urban1 iYf_T29 c30farm shown_1930 c30men c30black c30jap c30deu c30ita c30vet ///
	c30unemp c40unemp lc40wage iwarconpro_PC  if sample_ols == 1
	
	esttab . using "results/tables/Tab1_summary.tex",                                                          ///
			cells("mean(fmt(%9.3f) label(Mean)) sd(fmt(%9.3f) label(St. dev.)) count(fmt(%9.0f) label(Obs.))") ///
			nonumber noobs replace label                                                                       ///
			b(%9.3f) se(%9.3f)                                                                                 ///
			title("Summary statistics.")
restore

***************************************************************************************************
****     I. Tables                                                                             ****
****         Tab 2. New Deal and Patriotism: Basic Patterns                                    ****
****         	  a. Panel A   						                                           ****
***************************************************************************************************
estimates clear
eststo: xi:  reg iwarbond_1944_PC   iNDEXP_PC $control if sample_ols == 1                      , r beta
estadd local betacoef   = string(r(PT)[1,6], "%9.3f")

	    qui: sum iwarbond_1944_PC   if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iNDEXP_PC          if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))
estadd local IQR_X = string(`iqr_x', "%9.3f")

	   local IQR_Xbeta    = `iqr_x'*_b[iNDEXP_PC]
estadd local sIQR_Xbeta   = string(`IQR_Xbeta', "%9.3f")

	   local IQR_XbetadY  = (`IQR_Xbeta'/`iqr_y')*100
estadd local sIQR_XbetadY = string(`IQR_XbetadY', "%9.1f") + "\%"

eststo: xi:  reg ww2_vol_pop40      iNDEXP_PC $control if sample_ols == 1 & servicecommand != 7, r beta
estadd local betacoef   = string(r(PT)[1,6], "%9.3f")
	    qui: sum ww2_vol_pop40      if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iNDEXP_PC          if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))
estadd local IQR_X = string(`iqr_x', "%9.3f")

	   local IQR_Xbeta    = `iqr_x'*_b[iNDEXP_PC]
estadd local sIQR_Xbeta   = string(`IQR_Xbeta', "%9.3f")

	   local IQR_XbetadY  = (`IQR_Xbeta'/`iqr_y')*100
estadd local sIQR_XbetadY = string(`IQR_XbetadY', "%9.1f") + "\%"


eststo: xi:  reg ww2_awards_pop40_is iNDEXP_PC $control if sample_ols == 1 & servicecommand != 7, r beta
estadd local betacoef   = string(r(PT)[1,6], "%9.3f")
	    qui: sum ww2_awards_pop40_is if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
	   
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iNDEXP_PC          if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))
estadd local IQR_X = string(`iqr_x', "%9.3f")

	   local IQR_Xbeta    = `iqr_x'*_b[iNDEXP_PC]
estadd local sIQR_Xbeta   = string(`IQR_Xbeta', "%9.3f")

	   local IQR_XbetadY  = (`IQR_Xbeta'/`iqr_y')*100
estadd local sIQR_XbetadY = string(`IQR_XbetadY', "%9.1f") + "\%"

eststo: xi:  reg pc1                iNDEXP_PC $control if sample_ols == 1 & servicecommand != 7, r beta
estadd local betacoef   = string(r(PT)[1,6], "%9.3f")

	    qui: sum pc1                if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iNDEXP_PC          if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))
estadd local IQR_X = string(`iqr_x', "%9.3f")

	   local IQR_Xbeta    = `iqr_x'*_b[iNDEXP_PC]
estadd local sIQR_Xbeta   = string(`IQR_Xbeta', "%9.3f")

	   local IQR_XbetadY  = (`IQR_Xbeta'/`iqr_y')*100
estadd local sIQR_XbetadY = string(`IQR_XbetadY', "%9.1f") + "\%"

esttab using "results/tables/Tab2_main-a.tex" ,	                                                           ///
	order(iNDEXP_PC           )           				  		                                           ///
	drop(_cons)                                                                                            ///
	indicate("County-level controls = $control_nofe" "State FE (48) = *state*")                   		   ///
	mgroups("War bonds" "Volunteers" "Medals" "PCA" , pattern(1 1 1 1 )                                    ///
			prefix(\multicolumn{@span}{c}{) suffix(})                                                      ///
			span erepeat(\cmidrule(lr){@span}) )			                                               ///
	replace br se  label star(* 0.10 ** 0.05 *** 0.01) obslast nomtitles  compress longtable 	           ///
    scalars("y_mean_round Mean dependent variable" "sIQR_Xbeta New Deal grant IQR $\times$ $\beta$" "sIQR_XbetadY New Deal grant IQR $\times$ $\beta$ / IQR dep. var" "betacoef Beta-coefficient")                                                       ///
	b(%9.3f) se(%9.3f) r2(%9.3f)                                                                           ///
	nonotes nogaps title("New Deal and Patriotism: Basic Patterns (Panel A).")

***************************************************************************************************
****         	  b. Panel B   						                                           ****
***************************************************************************************************

estimates clear
eststo: xi:  reg iwarbond_1944_PC    iAGRI_PF iSSA_PB iinfra_AL EW_AL    iHOLC_PH iRFC_PC $control if sample_ols == 1                      , r
	    qui: sum iwarbond_1944_PC   if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")
eststo: xi:  reg ww2_vol_pop40       iAGRI_PF iSSA_PB iinfra_AL EW_AL    iHOLC_PH iRFC_PC $control if sample_ols == 1 & servicecommand != 7, r
	    qui: sum ww2_vol_pop40      if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")
eststo: xi:  reg ww2_awards_pop40_is iAGRI_PF iSSA_PB iinfra_AL EW_AL    iHOLC_PH iRFC_PC $control if sample_ols == 1 & servicecommand != 7, r
	    qui: sum ww2_awards_pop40_is if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")
eststo: xi:  reg pc1                 iAGRI_PF iSSA_PB iinfra_AL EW_AL    iHOLC_PH iRFC_PC $control if sample_ols == 1 & servicecommand != 7, r
	    qui: sum pc1                if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")

esttab using "results/tables/Tab2_main-b.tex" ,	                                   				           ///
	order(iAGRI_PF iSSA_PB iinfra_AL EW_AL    iHOLC_PH iRFC_PC )           				  	               ///
	indicate("County controls = $control_nofe" "State FE (48) = *state*")                   		       ///
	drop(_cons)                                                                                            ///
	mgroups("War bonds" "Volunteers" "Medals" "PCA" , pattern(1 1 1 1 )                                    ///
			prefix(\multicolumn{@span}{c}{) suffix(})                                                      ///
			span erepeat(\cmidrule(lr){@span}) )			                                               ///
	replace br se  label star(* 0.10 ** 0.05 *** 0.01) obslast nomtitles  compress longtable 	           ///
    scalars("y_mean_round Mean dependent variable" )                                                       ///
	b(%9.3f) se(%9.3f) r2(%9.3f)                                                                           ///
	nonotes nogaps title("New Deal and Patriotism: Basic Patterns (Panel B).")
	
***************************************************************************************************
****         Tab 3. New Deal Support and Patriotism: Individual-Level Results                  ****
****         	  a. Panel D   						                                           ****
***************************************************************************************************

use "tmp/asn", clear

qui reghdfe vol  iAAA_PF_farmer iAAA_PF_farmhand                                   farmer farmhand $controls_asn, absorb(countyn)
gen insample = e(sample) == 1

estimates clear
eststo: xi: reghdfe vol  iAAA_PF_farmer iAAA_PF_farmhand i.C40AGE                           farmer farmhand 				                      if insample == 1, cluster(countyn)  absorb(countyn)
       qui:    sum  vol if e(sample) == 1
	estadd local y_mean_round = string(r(mean), "%9.3f")
	estadd local sample       = "Army"
	estadd local fe           = "County"

eststo: xi: reghdfe vol  iAAA_PF_farmer iAAA_PF_farmhand                                   farmer farmhand $controls_asn                      	 if insample == 1, cluster(countyn) absorb(countyn)
       qui:    sum  vol if e(sample) == 1
	estadd local y_mean_round = string(r(mean), "%9.3f")
	estadd local sample       = "Army"
	estadd local fe           = "County"

eststo: xi: reghdfe vol  iAAA_PF_farmer iAAA_PF_farmhand                                  farmer farmhand $controls_asn                      	 if insample == 1 & (cem_matched_farmer == 1 | cem_matched_farmhand == 1), cluster(countyn) absorb(countyn)
       qui:    sum  vol if e(sample) == 1
	estadd local y_mean_round = string(r(mean), "%9.3f")
	estadd local sample       = "Army: CEM"
	estadd local fe           = "County"
	
esttab using  "results/tables/Tab3_main-d.tex"  ,	                                              	  ///
       indicate("Age FEs = *AGE*" "Individual controls (military) = $controls_asn_noage" )            ///
	   drop(_cons)                                                                                    ///
	   order(iAAA_PF_farmer iAAA_PF_farmhand farmer farmhand)   	 	             				  ///
		mgroups("Volunteer" , pattern(1 0 0)							  							  ///
		prefix(\multicolumn{@span}{c}{) suffix(})                                                	  ///
			span erepeat(\cmidrule(lr){@span}) )                  				     				  ///
		replace br se  label star(* 0.10 ** 0.05 *** 0.01) obslast nomtitles  	           			  ///
		scalars("fe Fixed effects" "sample Sample:" "y_mean_round Mean dependent variable")           ///
		b(%9.3f) se(%9.3f) r2(%9.3f) collabels(none) nonumber                                         ///
		nonotes nogaps nolegend title("New Deal and Patriotism: Basic Patterns (Panel D).")
		
***************************************************************************************************
****         Tab 4. Identification			                                    			   ****
***************************************************************************************************

use "tmp/patriot", clear

estimates clear
eststo: xi:  reg iAGRI_PF             iSUM3MO_DROUGHT3340 iAGRI_T73 $control               if sample_ols == 1                      , cluster(CLIMDIVX)
		qui: sum iAGRI_PF              if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")
		qui: test                    iSUM3MO_DROUGHT3340 iAGRI_T73 
estadd local F_test       = string(r(F)   , "%9.1f")

eststo: xi:  reg iwarbond_1944_PC    iSUM3MO_DROUGHT3340 iAGRI_T73 $control               if sample_ols == 1                      , cluster(CLIMDIVX)
		qui: sum iwarbond_1944_PC      if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")
eststo: xi:  reg ww2_vol_pop40       iSUM3MO_DROUGHT3340 iAGRI_T73 $control               if sample_ols == 1 & servicecommand != 7, cluster(CLIMDIVX)
		qui: sum ww2_vol_pop40         if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")
eststo: xi:  reg ww2_awards_pop40_is iSUM3MO_DROUGHT3340 iAGRI_T73 $control               if sample_ols == 1 & servicecommand != 7, cluster(CLIMDIVX)
		qui: sum ww2_awards_pop40_is    if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")
eststo: xi:  reg pc1                 iSUM3MO_DROUGHT3340 iAGRI_T73 $control               if sample_ols == 1 & servicecommand != 7, cluster(CLIMDIVX)
		qui: sum pc1                   if e(sample) == 1
estadd local y_mean_round = string(r(mean), "%9.3f")


eststo: xi:  ivreg2 iwarbond_1944_PC    (iAGRI_PF = iSUM3MO_DROUGHT3340 iAGRI_T73 ) $control if sample_ols == 1                      , cluster(CLIMDIVX) first
estadd local RA_test = string(`e(arfp)', "%4.3f")
		qui:   sum  iwarbond_1944_PC   if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iAGRI_PF              if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))*_b[iAGRI_PF]
estadd local IQR_X = string(`iqr_x', "%9.3f")
       local iqr_xdY       = (`iqr_x' / `iqr_y')*100
estadd local IQR_XY = string(`iqr_xdY', "%9.1f") + "\%"


eststo: xi:  ivreg2 ww2_vol_pop40       (iAGRI_PF = iSUM3MO_DROUGHT3340 iAGRI_T73 ) $control if sample_ols == 1 & servicecommand != 7, cluster(CLIMDIVX) first
estadd local RA_test = string(`e(arfp)', "%4.3f")
		qui:   sum  ww2_vol_pop40      if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iAGRI_PF              if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))*_b[iAGRI_PF]
estadd local IQR_X = string(`iqr_x', "%9.3f")
       local iqr_xdY       = (`iqr_x' / `iqr_y')*100
estadd local IQR_XY = string(`iqr_xdY', "%9.1f") + "\%"

eststo: xi:  ivreg2 ww2_awards_pop40_is (iAGRI_PF = iSUM3MO_DROUGHT3340 iAGRI_T73 ) $control if sample_ols == 1 & servicecommand != 7, cluster(CLIMDIVX) first
estadd local RA_test = string(`e(arfp)', "%4.3f")
		qui:   sum  ww2_awards_pop40_is if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iAGRI_PF              if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))*_b[iAGRI_PF]
estadd local IQR_X = string(`iqr_x', "%9.3f")
       local iqr_xdY       = (`iqr_x' / `iqr_y')*100
estadd local IQR_XY = string(`iqr_xdY', "%9.1f") + "\%"

eststo: xi:  ivreg2 pc1                 (iAGRI_PF = iSUM3MO_DROUGHT3340 iAGRI_T73 ) $control if sample_ols == 1 & servicecommand != 7, cluster(CLIMDIVX) first
estadd local RA_test = string(`e(arfp)', "%4.3f")
		qui:   sum  pc1                if e(sample) == 1, d
estadd local y_mean_round = string(r(mean), "%9.3f")
       local iqr_y       = (r(p75) - r(p25))
estadd local IQR_Y = string(`iqr_y', "%9.3f")
	    qui: sum iAGRI_PF              if e(sample) == 1, d
       local iqr_x       = (r(p75) - r(p25))*_b[iAGRI_PF]
estadd local IQR_X = string(`iqr_x', "%9.3f")
       local iqr_xdY       = (`iqr_x' / `iqr_y')*100
estadd local IQR_XY = string(`iqr_xdY', "%9.1f") + "\%"

esttab using "results/tables/Tab4-id-summary.tex" ,  ///
indicate("County controls = $control_nofe" "State FE (48) = *state*")                   		                                   ///
	keep(iAGRI_PF iSUM3MO_DROUGHT3340 iAGRI_T73 ) order(iAGRI_PF iSUM3MO_DROUGHT3340 iAGRI_T73)                                    ///
	mgroups("Agri support" "War bonds" "Volunteers" "Medals" "PCA" "War bonds" "Volunteers" "Medals" "PCA", pattern(1 1 1 1 1 1 1 1 1) ///
			prefix(\multicolumn{@span}{c}{) suffix(})                                                                              ///
			span erepeat(\cmidrule(lr){@span}) )			                                                                       ///
	mlabel("FS" "RF" "RF" "RF" "RF" "2SLS" "2SLS" "2SLS" "2SLS")		                                                           ///
	scalars("F_test F-test of excluded instrument" "y_mean_round Mean dependent variable" "IQR_X Agri support IQR $\times$ $\beta$" "IQR_XY Agri support IQR $\times$ $\beta$ / IQR dep. var." "RA_test Rubin-Anderson test (p-value)") ///
	replace br se  label star(* 0.10 ** 0.05 *** 0.01) obslast nomtitles  compress longtable 	                                   ///
	b(%9.3f) se(%9.3f) r2(%9.3f)        nonotes                                                                                           ///
	nogaps title("Identification: instruments are 1933-40 droughts and tenure in the agri committee.") 
	
***************************************************************************************************
****         Tab 5. Identification: Individual level			                               ****
***************************************************************************************************

***************************************************************************************************
****         	  a. Cols. 2 + 4   						                                       ****
***************************************************************************************************

use "tmp/asn", clear

qui reghdfe vol  iAAA_PF_farmer iAAA_PF_farmhand                                   farmer farmhand $controls_asn, absorb(countyn)
gen insample = e(sample) == 1

estimates clear
eststo: xi:    reghdfe  vol  iSUM3MO_DROUGHT3340_farmer iAGRI_T73_farmer iSUM3MO_DROUGHT3340_farmhand iAGRI_T73_farmhand farmer farmhand $controls_asn if insample == 1, cluster(countyn) absorb(countyn)
       qui:    sum  vol if e(sample) == 1
	estadd local y_mean_round = string(r(mean), "%9.3f")
	estadd local fe       	  = "Yes"
	estadd local sample       = "Army"
	
eststo: xi:  ivreghdfe vol (iAAA_PF_farmer iAAA_PF_farmhand  = iSUM3MO_DROUGHT3340_farmer iAGRI_T73_farmer iSUM3MO_DROUGHT3340_farmhand iAGRI_T73_farmhand) farmer farmhand $controls_asn  if insample == 1, cluster(countyn) absorb(countyn)
       qui:    sum  vol if e(sample) == 1
	estadd local y_mean_round = string(r(mean), "%9.3f")
	estadd local fe       	  = "Yes"
	estadd local sample       = "Army"
	
esttab using "results/tables/Tab5-id-b.tex" ,	                              	                          ///
indicate("Age FEs = *AGE*" "Individual controls (military) = $controls_asn_noage") 						  ///
		order(iAAA_PF_farmer iAAA_PF_farmhand iSUM3MO_DROUGHT3340_farmer iAGRI_T73_farmer iSUM3MO_DROUGHT3340_farmhand iAGRI_T73_farmhand farmer farmhand)  ///
		mgroups("Volunteer" , pattern(1 0)							       								  ///
		prefix(\multicolumn{@span}{c}{) suffix(})                                                         ///
			span erepeat(\cmidrule(lr){@span}) )			                               				  ///
		mlabel("RF" "2SLS" )                                                              			 	  ///
	scalars("fe County FEs" "y_mean_round Mean dependent variable" "sample Sample:")    				  ///
	replace br se  label star(* 0.10 ** 0.05 *** 0.01) obslast nomtitles nonum compress 	              ///
	b(%9.3f) se(%9.3f) r2(%9.3f) nonotes                                                                         ///
	nogaps title("Identification Table: Individual-Level.")
	

***************************************************************************************************
****     II. Figures                                                                           ****
***************************************************************************************************

***************************************************************************************************
****         Fig 1. New Deal Spending and WW II Patriotism			                           ****
***************************************************************************************************

use "tmp/patriot", clear

preserve
	keep if sample_ols == 1 & iwarbond_1944_PC != . & iNDEXP_PC != . & ww1_vol_sh != . & ww1_awards_pop10_is != .
	reg iwarbond_1944_PC ww1_vol_sh ww1_awards_pop10_is 
	predict e, resid
	xtile iNDEXP_PC_50 = iNDEXP_PC , n(50)
	collapse (mean) e iNDEXP_PC , by(iNDEXP_PC_50)
	twoway (scatter e                iNDEXP_PC , mfcolor(none) mlcolor(black)) ///
		   (lfit    e                iNDEXP_PC , lcolor(red)                 ), ylabel( , format(%2.1f) labsize(large) angle(0) grid) legend(off) xlabel(4 "4" 5 "5" 6 "6" 7 "7", grid labsize(large)) xtitle(New Deal $ p.c. (ihs), size(*1.2)) ytitle(, size(large)) title(A. War bonds, size(huge))  name(g1, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
restore

preserve
	keep if sample_ols == 1 & ww2_vol_pop40 != . & iNDEXP_PC != . & servicecommand != 7 & ww1_vol_sh != . & ww1_awards_pop10_is != .
	reg ww2_vol_pop40 ww1_vol_sh ww1_awards_pop10_is 
	predict e, resid
	xtile iNDEXP_PC_50 = iNDEXP_PC , n(50)
	collapse (mean) e iNDEXP_PC , by(iNDEXP_PC_50)
	twoway (scatter e iNDEXP_PC , mfcolor(none) mlcolor(black)) ///
		   (lfit    e iNDEXP_PC , lcolor(red)                 ), ylabel( , format(%3.2f) labsize(large) angle(0) grid) legend(off) xlabel(4 "4" 5 "5" 6 "6" 7 "7", grid labsize(large)) xtitle(New Deal $ p.c. (ihs), size(*1.2)) ytitle(, size(large)) title(B. Volunteers, size(huge)) name(g2, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
restore

preserve
	keep if sample_ols == 1 & ww2_awards_pop40_is != . & iNDEXP_PC != . & servicecommand != 7 & ww1_vol_sh != . & ww1_awards_pop10_is != .
	reg ww2_vol_pop40 ww1_vol_sh ww1_awards_pop10_is 
	predict e, resid
	xtile iNDEXP_PC_50 = iNDEXP_PC , n(50)
	collapse (mean) e iNDEXP_PC , by(iNDEXP_PC_50)
	twoway (scatter e iNDEXP_PC , mfcolor(none) mlcolor(black)) ///
		   (lfit    e iNDEXP_PC , lcolor(red)                 ), ylabel( , format(%2.1f) labsize(large) angle(0) grid) legend(off) xlabel(4 "4" 5 "5" 6 "6" 7 "7", grid labsize(large)) xtitle(New Deal $ p.c.  (ihs), size(*1.2)) ytitle(, size(large)) title(C. Medals, size(huge))  name(g3, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
restore

graph combine g1 g2 g3, r(1) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
graph drop    g1 g2 g3
graph export "results/figures/Fig1_main.pdf", replace as(pdf)
graph export "results/figures/Fig1_main.png", replace as(png)

***************************************************************************************************
****         Fig 2. Geographic Distribution of Main Variables			                       ****
***************************************************************************************************
format iwarbond_1944_PC ww2_vol_pop40    ww2_awards_pop40_is iNDEXP_PC iAGRI_PF %2.1f
format iAGRI_PF iSUM3MO_DROUGHT3340 %2.1f
ren _ID_CA _ID
***************************************************************************************************
****              a. War bonds                                              				   ****
***************************************************************************************************
spmap  iwarbond_1944_PC using data/C-CountiesND_CA, id(_ID) fcolor(Blues2) clnumber(9) ndocolor(none) ocolor(none ..)  		      ///
               legend( position(5) bplacement(sw) r(5))                                                                			  ///
			line(data(data/C-USA_CA)) title(A. War bonds, size(*1.4))
graph export "results/figures/Fig2A_map-bonds.png", as(png) replace
graph export "results/figures/Fig2A_map-bonds.pdf", as(pdf) replace
						
***************************************************************************************************
****              b. Volunteers                                                                ****
***************************************************************************************************
spmap  ww2_vol_pop40          using data/C-CountiesND_CA, id(_ID) fcolor(Blues2) clnumber(9) ndocolor(none) ocolor(none ..) 	  ///
               legend( position(5) bplacement(sw) r(5))                                                                           ///
			polygon(data(data/C-ServiceCommand7) osize(vthick)) line(data(data/C-USA_CA)) title(B. Volunteers, size(*1.4)) 
graph export "results/figures/Fig2B_map-volunteers.png", as(png) replace
graph export "results/figures/Fig2B_map-volunteers.pdf", as(pdf) replace

***************************************************************************************************
****              c. Medals                                                 				   ****
***************************************************************************************************
spmap  ww2_awards_pop40_is using data/C-CountiesND_CA, id(_ID) fcolor(Blues2) clnumber(9) ndocolor(none) ocolor(none ..)  		///
               legend( position(5) bplacement(sw) r(5))                                                                         ///
			polygon(data(data/C-ServiceCommand7) osize(vthick)) line(data(data/C-USA_CA)) title(C. Medals, size(*1.4))
graph export "results/figures/Fig2C_map-medals.png", as(png) replace
graph export "results/figures/Fig2C_map-medals.pdf", as(pdf) replace

***************************************************************************************************
****              d. New Deal grants                                        			       ****
***************************************************************************************************
spmap  iNDEXP_PC        using data/C-CountiesND_CA, id(_ID) fcolor(Reds2) clnumber(9) ndocolor(none) ocolor(none ..)     		 ///
               legend( position(5) bplacement(sw) r(5))                                                                          ///
			line(data(data/C-USA_CA)) title(D. New Deal grants, size(*1.4))
graph export "results/figures/Fig2D_map-grants.png", as(png) replace
graph export "results/figures/Fig2D_map-grants.pdf", as(pdf) replace

***************************************************************************************************
****              e. Agricultural support                                   				   ****
***************************************************************************************************

spmap  iAGRI_PF            using data/C-CountiesND_CA, id(_ID) fcolor(Greens2) clnumber(9) ndocolor(none) ocolor(none ..)  ///
               legend( position(5) bplacement(sw) r(5))                                                                          ///
			line(data(data/C-USA_CA)) title(E. Agricultural support, size(*1.4))
graph export "results/figures/Fig2E_map-aaa.png", as(png) replace
graph export "results/figures/Fig2E_map-aaa.pdf", as(pdf) replace
						
***************************************************************************************************
****              f. Droughts                                               				   ****
***************************************************************************************************
spmap  iSUM3MO_DROUGHT3340 using data/C-CountiesND_CA, id(_ID) fcolor(Greys2) clnumber(9) ndocolor(none) ocolor(none ..)  ///
               legend( position(5) bplacement(sw) r(5))                                                                         ///
			line(data(data/C-USA_CA)) title(F. Droughts, size(*1.4))
graph export "results/figures/Fig2F_map-droughts.png", as(png) replace
graph export "results/figures/Fig2F_map-droughts.pdf", as(pdf) replace

***************************************************************************************************
****         Fig 3. Identification										                       ****
***************************************************************************************************
***************************************************************************************************
****             a. Droughts                                            				       ****
***************************************************************************************************
preserve
	keep if sample_ols == 1 & iAGRI_PF != . & iSUM3MO_DROUGHT3340!= .
	xtile iSUM3MO_DROUGHT3340_50 = iSUM3MO_DROUGHT3340 , n(50)
	collapse (mean) iAGRI_PF iSUM3MO_DROUGHT3340 , by(iSUM3MO_DROUGHT3340_50)
	format iAGRI_PF iSUM3MO_DROUGHT3340 %2.1f
	twoway (scatter iAGRI_PF iSUM3MO_DROUGHT3340 , mfcolor(none) mlcolor(black)) ///
		   (lfit    iAGRI_PF iSUM3MO_DROUGHT3340 , lcolor(red)                 ), ylabel( , format(%2.1f) angle(0) labsize(large)) legend(off) xlabel(0(1)3, format(%2.0f) grid labsize(large)) xtitle(New Deal drought, size(large)) ytitle(" ") title(A. Agricultural support, size(huge))  ylabel( , grid labsize(large)) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) name(g1, replace) 
restore

preserve
	keep if sample_ols == 1 & iwarbond_1944_PC != . & iSUM3MO_DROUGHT3340 != . & ww1_vol_sh != . & ww1_awards_pop10_is != .
	reg iwarbond_1944_PC ww1_vol_sh ww1_awards_pop10_is 
	predict e, resid
	xtile iSUM3MO_DROUGHT3340_50 = iSUM3MO_DROUGHT3340 , n(50)
	collapse (mean) e iSUM3MO_DROUGHT3340 , by(iSUM3MO_DROUGHT3340_50)
	twoway (scatter e iSUM3MO_DROUGHT3340 , mfcolor(none) mlcolor(black)) ///
		   (lfit    e iSUM3MO_DROUGHT3340 , lcolor(red)                 ), ylabel( , format(%2.1f) labsize(large) angle(0) grid) legend(off) xlabel(0(1)3, grid labsize(large)) xtitle(New Deal drought, size(large)) ytitle(, size(large)) title(B. War bonds, size(huge))  name(g2, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual)
restore

preserve
	keep if sample_ols == 1 & ww2_vol_pop40 != . & iSUM3MO_DROUGHT3340 != . & servicecommand != 7 & ww1_vol_sh != . & ww1_awards_pop10_is != .
	reg ww2_vol_pop40 ww1_vol_sh ww1_awards_pop10_is 
	predict e, resid
	xtile iSUM3MO_DROUGHT3340_50 = iSUM3MO_DROUGHT3340 , n(50)
	collapse (mean) e iSUM3MO_DROUGHT3340 , by(iSUM3MO_DROUGHT3340_50)
	twoway (scatter e iSUM3MO_DROUGHT3340 , mfcolor(none) mlcolor(black)) ///
		   (lfit    e iSUM3MO_DROUGHT3340 , lcolor(red)                 ), ylabel( , format(%2.1f) labsize(large) angle(0) grid) legend(off) xlabel(0(1)3, grid labsize(large)) xtitle(New Deal drought, size(large)) ytitle(, size(large)) title(C. Volunteers, size(huge)) name(g3, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
restore


preserve
	keep if sample_ols == 1 & ww2_awards_pop40_is != . & iSUM3MO_DROUGHT3340 != . & servicecommand != 7 & ww1_vol_sh != . & ww1_awards_pop10_is != .
	reg ww2_awards_pop40_is ww1_vol_sh ww1_awards_pop10_is 
	predict e, resid
	xtile iSUM3MO_DROUGHT3340_50 = iSUM3MO_DROUGHT3340 , n(50)
	collapse (mean) e iSUM3MO_DROUGHT3340 , by(iSUM3MO_DROUGHT3340_50)
	twoway (scatter e iSUM3MO_DROUGHT3340 , mfcolor(none) mlcolor(black)) ///
		   (lfit    e iSUM3MO_DROUGHT3340 , lcolor(red)                 ), ylabel( , format(%3.2f) labsize(large) angle(0) grid) legend(off) xlabel(0(1)3, grid labsize(large)) xtitle(New Deal drought, size(large)) ytitle(, size(large)) title(D. Medals, size(huge))  name(g4, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
restore
graph combine g1 g2 g3 g4, r(2) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
graph export "results/figures/Fig3A-D_id-droughts.png", as(png) replace
graph export "results/figures/Fig3A-D_id-droughts.pdf", as(pdf) replace
graph drop    g1 g2 g3 g4

***************************************************************************************************
****             b. Committees                                            		     		   ****
***************************************************************************************************
preserve
	keep if sample_ols == 1 & iAGRI_PF != . & iAGRI_T73 != . 
	areg iAGRI_T73 , absorb(stateicpsr)
	predict x, resid
	areg iAGRI_PF , absorb(stateicpsr)
	predict y, resid
	
	xtile x_50 = x , n(50)
	collapse (mean) y x , by(x_50)
	format y x %2.1f
	twoway (scatter y x , mfcolor(none) mlcolor(black)) ///
		   (lfit    y x , lcolor(red)                 ), ylabel( , grid format(%2.1f) angle(0) labsize(large)) legend(off) xlabel( , format(%2.1f)  grid labsize(large)) xtitle(Tenure agri committee, size(large)) ytitle(" ") title(E. Agricultural support, size(huge))  ylabel( , grid labsize(large)) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) name(g1, replace) 
restore

preserve
	keep if sample_ols == 1 & iwarbond_1944_PC != . & iAGRI_T73 != . & ww1_vol_sh != . & ww1_awards_pop10_is != .
	areg iAGRI_T73 , absorb(stateicpsr)
	predict x, resid
	areg iwarbond_1944_PC ww1_vol_sh ww1_awards_pop10_is  , absorb(stateicpsr)
	predict y, resid
	
	xtile x_50 = x , n(50)
	collapse (mean) y x , by(x_50)
	format y x %2.1f
	twoway (scatter y x , mfcolor(none) mlcolor(black)) ///
		   (lfit    y x , lcolor(red)                 )	, ylabel( , format(%2.1f) labsize(large) angle(0) grid) legend(off) xlabel(, grid labsize(large)) xtitle(Tenure agri committee, size(large)) ytitle(, size(large)) title(F. War bonds, size(huge))  name(g2, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual)
restore

preserve
	keep if sample_ols == 1 & ww2_vol_pop40 != . & iAGRI_T73 != . & servicecommand != 7 & ww1_vol_sh != . & ww1_awards_pop10_is != .
	areg iAGRI_T73 , absorb(stateicpsr)
	predict x, resid
	areg ww2_vol_pop40 ww1_vol_sh ww1_awards_pop10_is , absorb(stateicpsr)
	predict y, resid
	
	xtile x_50 = x , n(50)
	collapse (mean) y x , by(x_50)
	format y x %2.1f
	twoway (scatter y x , mfcolor(none) mlcolor(black)) ///
		   (lfit    y x , lcolor(red)                 )	, ylabel( , format(%2.1f) labsize(large) angle(0) grid) legend(off) xlabel(, grid labsize(large)) xtitle(Tenure agri committee, size(large)) ytitle(, size(large)) title(G. Volunteers, size(huge)) name(g3, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
restore


preserve
	keep if sample_ols == 1 & ww2_awards_pop40_is != . & iAGRI_T73 != . & servicecommand != 7 & ww1_vol_sh != . & ww1_awards_pop10_is != .
	areg iAGRI_T73 , absorb(stateicpsr)
	predict x, resid
	areg ww2_awards_pop40_is ww1_vol_sh ww1_awards_pop10_is , absorb(stateicpsr)
	predict y, resid
	
	xtile x_50 = x , n(50)
	collapse (mean) y x , by(x_50)
	format y x %2.1f
	twoway (scatter y x , mfcolor(none) mlcolor(black)) ///
		   (lfit    y x , lcolor(red)                 )	, ylabel( , format(%3.2f) labsize(large) angle(0) grid) legend(off) xlabel(, grid labsize(large)) xtitle(Tenure agri committee, size(large)) ytitle(, size(large)) title(H. Medals, size(huge))  name(g4, replace) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
restore
graph combine g1 g2 g3 g4, r(2) plotregion(fcolor(white)) graphregion(fcolor(white)) scheme(s1manual) 
graph drop    g1 g2 g3 g4
graph export "results/figures/Fig3E-H_id-committee.png", as(png) replace
graph export "results/figures/Fig3E-H_id-committee.pdf", as(pdf) replace

***************************************************************************************************
****         Fig 4. Pre-New Deal Droughts										               ****
***************************************************************************************************
***************************************************************************************************
****                 a. Droughts and AAA spending overtime                  				   ****
***************************************************************************************************

preserve
	use C:/X/patriot, replace
	keep if sample_ols == 1
	keeporder stateicpsr countynd SUM3MO_DROUGHT1897 SUM3MO_DROUGHT1898 SUM3MO_DROUGHT1899 SUM3MO_DROUGHT1900 SUM3MO_DROUGHT1901 SUM3MO_DROUGHT1902 SUM3MO_DROUGHT1903 SUM3MO_DROUGHT1904 SUM3MO_DROUGHT1905 SUM3MO_DROUGHT1906 SUM3MO_DROUGHT1907 SUM3MO_DROUGHT1908 SUM3MO_DROUGHT1909 SUM3MO_DROUGHT1910 SUM3MO_DROUGHT1911 SUM3MO_DROUGHT1912 SUM3MO_DROUGHT1913 SUM3MO_DROUGHT1914 SUM3MO_DROUGHT1915 SUM3MO_DROUGHT1916 SUM3MO_DROUGHT1917 SUM3MO_DROUGHT1918 SUM3MO_DROUGHT1919 SUM3MO_DROUGHT1920 SUM3MO_DROUGHT1921 SUM3MO_DROUGHT1922 SUM3MO_DROUGHT1923 SUM3MO_DROUGHT1924 SUM3MO_DROUGHT1925 SUM3MO_DROUGHT1926 SUM3MO_DROUGHT1927 SUM3MO_DROUGHT1928 SUM3MO_DROUGHT1929 SUM3MO_DROUGHT1930 SUM3MO_DROUGHT1931 SUM3MO_DROUGHT1932 SUM3MO_DROUGHT1933 SUM3MO_DROUGHT1934 SUM3MO_DROUGHT1935 SUM3MO_DROUGHT1936 SUM3MO_DROUGHT1937 SUM3MO_DROUGHT1938 SUM3MO_DROUGHT1939 SUM3MO_DROUGHT1940 
	reshape long SUM3MO_DROUGHT, i(stateicpsr countynd) j(Year) string
	
	destring Year, replace
	
	collapse (mean) SUM3MO_DROUGHT, by(Year)
	gen newdeal     =  1.3 if Year == 1936
	gen newdeal_lab = "New Deal"

	format SUM3MO_DROUGHT %2.0f
	
	twoway (scatter SUM3MO_DROUGHT Year, mc(black) mfc(none) msize(medsmall))                         ///
		   (scatter newdeal        Year, mlabel(newdeal_lab) mlabcolor(blue) mlabsize(medsmall) m(i)) /// 
		   (line    SUM3MO_DROUGHT Year, lc(black)),                                                 ///
		   xlab(1897 "1897" 1901 "1901" 1905 "1905" 1909 "1909" 1913 "1913" 1917 "1917" 1921 "1921" 1925 "1925" 1929 "1929" 1933 "1933" 1937 "1937" 1941 "1941", angle(45) labsize(large)) xtitle("") xline(1932.5, lcolor(blue) lp(dash)) ///
		 ylab(, format(%2.1f) angle(0) labsize(large)) ytitle("") title(A. Summer months with drought, size(huge)) plotregion(color(white)) graphregion(color(white)) legend(off) name(g2, replace) 
	graph export "results/figures/Fig4A_pre-droughts-byyear.png", replace as(png)
	graph export "results/figures/Fig4A_pre-droughts-byyear.pdf", replace as(pdf)
restore


preserve
	use rawdata/Libecap/Libecap, clear

	gen newdeal     =  0.025 if Year == 1933
	gen newdeal_lab = "New Deal"
	
	twoway (scatter Share   Year, mc(black) mfc(none) msize(medsmall))                         ///
		   (scatter newdeal Year, mlabel(newdeal_lab) mlabcolor(blue) mlabsize(medsmall) m(i)) /// 
		   (line    Share   Year, lc(black)), xlab(1901 "1901" 1905 "1905" 1909 "1909" 1913 "1913" 1917 "1917" 1921 "1921" 1925 "1925" 1929 "1929" 1933 "1933" 1937 "1937" 1941 "1941", angle(45)  labsize(normalsize)) ylab(0 "0%" 0.1 "10%" 0.2 "20%", angle(0) labsize(large)) xtitle(" ") ytitle(" ") xline(1932.5, lcolor(blue) lp(dash)) title(B. Public spending: share agriculture, size(huge)) plotregion(color(white)) graphregion(color(white)) legend(off) name(g1, replace) 
	graph export "results/figures/Fig4B_pre-aaa-Libecap.png", replace as(png)
	graph export "results/figures/Fig4B_pre-aaa-Libecap.pdf", replace as(pdf)
restore

***************************************************************************************************
****                b. Patriotism and pre-New Deal droughts                  				   ****
***************************************************************************************************

tab stateicpsr, gen(state)

local dependents iAGRI_PF_Z iwarbond_1944_PC_Z ww2_vol_pop40_Z ww1_vol_pop10_Z ww2_awards_pop40_is_Z ww1_awards_pop10_is_Z
graph close _all    
foreach dependent of local dependents {
	local drought_title "Summer months of droughts (i.h.s.)"
	local drought_name  "logsum3"
	local drought_pre   "iSUM3MO_DROUGHT"
	
	if "`dependent'" == "iAGRI_PF_Z"    		local           title "C. Agricultural support"
	if "`dependent'" == "iwarbond_1944_PC_Z"    local           title "D. War bonds"
	if "`dependent'" == "ww2_vol_pop40_Z"       local           title "E. Volunteers (WWII)"
	if "`dependent'" == "ww2_awards_pop40_is_Z" local           title "F. Medals (WWII)"
	if "`dependent'" == "ww1_vol_pop10_Z"       local           title "G. Volunteers (WWI)"
	if "`dependent'" == "ww1_awards_pop10_is_Z" local           title "H. Medals (WWI)"

	if "`dependent'" == "iAGRI_PF_Z"    		local dependent_title "AAA"
	if "`dependent'" == "iwarbond_1944_PC_Z"    local dependent_title "bond"
	if "`dependent'" == "ww1_vol_pop10_Z"       local dependent_title "volunteer_wwi"
	if "`dependent'" == "ww2_vol_pop40_Z"       local dependent_title "volunteer_wwii"
	if "`dependent'" == "ww1_awards_pop10_is_Z" local dependent_title "medal_wwi"
	if "`dependent'" == "ww2_awards_pop40_is_Z" local dependent_title "medal_wwii"
	
	if "`dependent'" == "iAGRI_PF_Z"    		local if 				
	if "`dependent'" == "iwarbond_1944_PC_Z"    local if
	if "`dependent'" == "ww1_vol_pop10_Z"       local if 				
	if "`dependent'" == "ww2_vol_pop40_Z"       local if 				"& servicecommand != 7"
	if "`dependent'" == "ww1_awards_pop10_is_Z" local if 				
	if "`dependent'" == "ww2_awards_pop40_is_Z" local if 				"& servicecommand != 7"
	
	if "`dependent'" == "iAGRI_PF_Z"    		local droughtlist 	"iSUM3MO_DROUGHT9700_Z iSUM3MO_DROUGHT0104_Z iSUM3MO_DROUGHT0508_Z iSUM3MO_DROUGHT0912_Z iSUM3MO_DROUGHT1316_Z iSUM3MO_DROUGHT1720_Z iSUM3MO_DROUGHT2124_Z iSUM3MO_DROUGHT2528_Z iSUM3MO_DROUGHT2932_Z iSUM3MO_DROUGHT3340_Z"			
	if "`dependent'" == "iwarbond_1944_PC_Z"    local droughtlist 	"iSUM3MO_DROUGHT9700_Z iSUM3MO_DROUGHT0104_Z iSUM3MO_DROUGHT0508_Z iSUM3MO_DROUGHT0912_Z iSUM3MO_DROUGHT1316_Z iSUM3MO_DROUGHT1720_Z iSUM3MO_DROUGHT2124_Z iSUM3MO_DROUGHT2528_Z iSUM3MO_DROUGHT2932_Z iSUM3MO_DROUGHT3340_Z"
	if "`dependent'" == "ww1_vol_pop10_Z"       local droughtlist 	"iSUM3MO_DROUGHT9700_Z iSUM3MO_DROUGHT0104_Z iSUM3MO_DROUGHT0508_Z iSUM3MO_DROUGHT0912_Z iSUM3MO_DROUGHT1316_Z"						
	if "`dependent'" == "ww2_vol_pop40_Z"       local droughtlist 	"iSUM3MO_DROUGHT9700_Z iSUM3MO_DROUGHT0104_Z iSUM3MO_DROUGHT0508_Z iSUM3MO_DROUGHT0912_Z iSUM3MO_DROUGHT1316_Z iSUM3MO_DROUGHT1720_Z iSUM3MO_DROUGHT2124_Z iSUM3MO_DROUGHT2528_Z iSUM3MO_DROUGHT2932_Z iSUM3MO_DROUGHT3340_Z"
	if "`dependent'" == "ww1_awards_pop10_is_Z" local droughtlist 	"iSUM3MO_DROUGHT9700_Z iSUM3MO_DROUGHT0104_Z iSUM3MO_DROUGHT0508_Z iSUM3MO_DROUGHT0912_Z iSUM3MO_DROUGHT1316_Z"						
	if "`dependent'" == "ww2_awards_pop40_is_Z" local droughtlist	"iSUM3MO_DROUGHT9700_Z iSUM3MO_DROUGHT0104_Z iSUM3MO_DROUGHT0508_Z iSUM3MO_DROUGHT0912_Z iSUM3MO_DROUGHT1316_Z iSUM3MO_DROUGHT1720_Z iSUM3MO_DROUGHT2124_Z iSUM3MO_DROUGHT2528_Z iSUM3MO_DROUGHT2932_Z iSUM3MO_DROUGHT3340_Z"
	
	if "`dependent'" == "iAGRI_PF_Z"    		local yy 			"9700 0104 0508 0912 1316 1720 2124 2528 2932 3340"			
	if "`dependent'" == "iwarbond_1944_PC_Z"    local yy 			"9700 0104 0508 0912 1316 1720 2124 2528 2932 3340"
	if "`dependent'" == "ww1_vol_pop10_Z"       local yy 			"9700 0104 0508 0912 1316"			
	if "`dependent'" == "ww2_vol_pop40_Z"       local yy 			"9700 0104 0508 0912 1316 1720 2124 2528 2932 3340"
	if "`dependent'" == "ww1_awards_pop10_is_Z" local yy 			"9700 0104 0508 0912 1316"					
	if "`dependent'" == "ww2_awards_pop40_is_Z" local yy			"9700 0104 0508 0912 1316 1720 2124 2528 2932 3340"	

	if "`dependent'" == "iAGRI_PF_Z"    		macro def control 	"ww1_vol_sh_Z ww1_awards_pop10_is_Z lpop30_Z c30unemp_Z c30urban1_Z c30farm_Z iYf_T29_Z MEAN9628_Z c30men_Z c30black_Z c30jap_Z c30deu_Z c30ita_Z c30vet_Z lc40wage_Z iwarconpro_PC_Z "			
	if "`dependent'" == "iwarbond_1944_PC_Z"    macro def control 	"ww1_vol_sh_Z ww1_awards_pop10_is_Z lpop30_Z c30unemp_Z c30urban1_Z c30farm_Z iYf_T29_Z MEAN9628_Z c30men_Z c30black_Z c30jap_Z c30deu_Z c30ita_Z c30vet_Z lc40wage_Z iwarconpro_PC_Z "
	if "`dependent'" == "ww1_vol_pop10_Z"       macro def control	"lpop10_Z c10unemp_Z c10urban1_Z c10men_Z c10black_Z c10jap_Z c10deu_Z c10ita_Z "			
	if "`dependent'" == "ww2_vol_pop40_Z"    	macro def control 	"ww1_vol_sh_Z ww1_awards_pop10_is_Z lpop30_Z c30unemp_Z c30urban1_Z c30farm_Z iYf_T29_Z MEAN9628_Z c30men_Z c30black_Z c30jap_Z c30deu_Z c30ita_Z c30vet_Z lc40wage_Z iwarconpro_PC_Z "
	if "`dependent'" == "ww1_awards_pop10_is_Z" macro def control	"lpop10_Z c10unemp_Z c10urban1_Z c10men_Z c10black_Z c10jap_Z c10deu_Z c10ita_Z "			
	if "`dependent'" == "ww2_awards_pop40_is_Z" macro def control 	"ww1_vol_sh_Z ww1_awards_pop10_is_Z lpop30_Z c30unemp_Z c30urban1_Z c30farm_Z iYf_T29_Z MEAN9628_Z c30men_Z c30black_Z c30jap_Z c30deu_Z c30ita_Z c30vet_Z lc40wage_Z iwarconpro_PC_Z"
	
	foreach spec in "$control"{
		if "`spec'" == "$control" 				 local spec_name       "(state FEs)"
		if "`spec'" == "$control" 				 local spec_title      "statefe"
		
		cap drop *_Z
		foreach d in iAGRI_PF iwarbond_1944_PC ww2_vol_pop40 ww1_vol_sh ww1_vol_pop10 ww2_awards_pop40_is ww1_awards_pop10_is{
			egen `d'_Z = std(`d') if sample_ols == 1 `if'
		}

		foreach d of var state1-state49{
			egen `d'_Z = std(`d') if sample_ols == 1 `if'
		}

		foreach d in lpop30 c30unemp c30urban1 c30farm iYf_T29 MEAN9628 c30men c30black c30jap c30deu c30ita c30vet lc40wage iwarconpro_PC{
			egen `d'_Z = std(`d') if sample_ols == 1 `if'
		}

		foreach d in lpop10 c10unemp c10urban1 c10men c10black c10jap c10deu c10ita{
			egen `d'_Z = std(`d') if sample_ols == 1 `if'
		}

		foreach d in iSUM3MO_DROUGHT9700 iSUM3MO_DROUGHT0104 iSUM3MO_DROUGHT0508 iSUM3MO_DROUGHT0912 iSUM3MO_DROUGHT1316 iSUM3MO_DROUGHT1720 iSUM3MO_DROUGHT2124 iSUM3MO_DROUGHT2528 iSUM3MO_DROUGHT2932 iSUM3MO_DROUGHT3340{
			egen `d'_Z = std(`d') if sample_ols == 1 `if'	
		}

drop state49_Z

if "`if'" == "& servicecommand != 7"{
	drop state16_Z state17_Z state18_Z state19_Z state20_Z state21_Z state22_Z state39_Z state45_Z
}	
estimates clear

xi: reg `dependent' `droughtlist' `spec'  state*_Z if sample_ols == 1  `if', cluster(CLIMDIVX)

	 foreach year in `yy'{
		local b_`dependent'_`year' = _b[`drought_pre'`year']
		local s_`dependent'_`year' = _se[`drought_pre'`year']
		} /* forvalues year */
		
preserve 

		clear
		set obs 20
		gen years = .
		gen b    = .
		gen s    = .
		gen l    =.
		gen h    =.
		gen ord  = ""
		local j 0

		foreach year in `yy'{
	
			if "`year'" == "9700"    local           years "1897-1900"
			if "`year'" == "0104"    local           years "1900-1904"
			if "`year'" == "0508" 	 local           years "1905-1908"
			if "`year'" == "0912"    local 			 years "1909-1912"
			if "`year'" == "1316"    local 			 years "1913-1916"
			if "`year'" == "1720"    local           years "1917-1920"
			if "`year'" == "2124"    local           years "1921-1924"
			if "`year'" == "2528" 	 local           years "1925-1928"
			if "`year'" == "2932"    local 			 years "1929-1932"
			if "`year'" == "3340"    local 			 years "1933-1940"

			local j =         	`j' + 1
			qui replace years = `j' 					  if _n==`j'
			qui replace ord = "`years'"    			  	  if _n == `j'
			qui replace b    = `b_`dependent'_`year''     if _n == `j'
			qui replace s    = `s_`dependent'_`year''     if _n == `j'
			qui replace l    =   b - 1.96 * s			  if _n == `j'
			qui replace h    =   b + 1.96 * s			  if _n == `j'
		} /* forvalues year */ 
		
		
	labmask years, val(ord)
	
	sort  years
	qui separate b, by(years)
	qui separate h, by(years)
	qui separate l, by(years)
	
	qui sum h
	
	local maxv`dependent' `r(max)'
	
	if "`maxvww1_vol_pop10_Z'" != "" & "`maxvww2_vol_pop40_Z'" != ""{
		local maxvww1_vol_pop10_Z = `maxvww2_vol_pop40_Z'
	}
	if "`maxvww2_awards_pop40_is_Z'" != "" & "`maxvww1_awards_pop10_is_Z'" != ""{
		local maxvww1_awards_pop10_is_Z = `maxvww2_awards_pop40_is_Z'
	}
	
	if "`yy'" == "9700 0104 0508 0912 1316 1720 2124 2528 2932 3340"{
				twoway (scatter b1	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
			   (scatter b2	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
		       (scatter b3	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
			   (scatter b4	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
			   (scatter b5	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  		     	///
			   (scatter b6	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
		       (scatter b7	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
			   (scatter b8	years,  mcolor(red%40) 	  mfcolor(none) msize(*0.8) msymbol(oh))  				///
			   (scatter b9	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
		       (scatter b10	years,  mcolor(red)    	  mfcolor(none) msize(*0.8) msymbol(oh))  				///
			   (rcap h1 l1	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
			   (rcap h2 l2	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///		   
			   (rcap h3 l3	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
			   (rcap h4 l4	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
			   (rcap h5 l5	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///	
			   (rcap h6 l6	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
			   (rcap h7 l7	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///		   
			   (rcap h8 l8	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))					///
			   (rcap h9 l9	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
			   (rcap h10 l10 years,  blcolor(red)     blwidth(medthick) blpattern(solid)),  				///		   
				legend(off) yline(0, lcolor(black)) xline(9.5, lcolor(navy) lpattern(dash)) 				///
				yscale(range(-`maxv`dependent'' `maxv`dependent'')) ylabel(-`maxv`dependent'' 0 `maxv`dependent'', angle(0) labsize(*1.4) format(%9.3f)) ytitle( ) 	   ///
				xlabel(1(1)10, valuelabel labsize(*1.1) angle(45)) xtitle("Months of droughts", size(large)) xscale(range(0.5 10.5)) title(`title', size(huge)) ///
				graphregion(fcolor(white)) plotregion(fcolor(white)) scheme(s1manual) name("`dependent_title'_`drought_name'_`spec_title'", replace)
		
		graph export "results/figures/Fig4C-H_pre-`dependent_title'.png", replace as(png)
		graph export "results/figures/Fig4C-H_pre-`dependent_title'.pdf", replace as(pdf)
	restore
	}
	
		if "`yy'" == "9700 0104 0508 0912 1316"{
			twoway (scatter b1	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
				   (scatter b2	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
				   (scatter b3	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
				   (scatter b4	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  				///
				   (scatter b5	years,  mcolor(red%40)    mfcolor(none) msize(*0.8) msymbol(oh))  		     	///
				   (rcap h1 l1	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
				   (rcap h2 l2	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///		   
				   (rcap h3 l3	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
				   (rcap h4 l4	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid))  					///
				   (rcap h5 l5	years,  blcolor(red%40)   blwidth(medthick) blpattern(solid)),					///
					legend(off) yline(0, lcolor(black))                  										///
					yscale(range(-`maxv`dependent'' `maxv`dependent'')) ylabel(-`maxv`dependent'' 0 `maxv`dependent'', angle(0) labsize(*1.4) format(%9.3f)) ytitle( )  ///
					xlabel(1(1)5, valuelabel labsize(*1.1) angle(45)) xtitle("Months of droughts", size(large)) xscale(range(0.5 5.5)) title(`title', size(huge)) ///
					graphregion(fcolor(white)) plotregion(fcolor(white)) scheme(s1manual) name("`dependent_title'_`drought_name'_`spec_title'", replace)
		
			graph export "results/figures/Fig4C-H_pre-`dependent_title'.png", replace as(png)
			graph export "results/figures/Fig4C-H_pre-`dependent_title'.pdf", replace as(pdf)
		restore	
		}
	}
}

***************************************************************************************************
****     III. Erase junk                                                                 	   ****      ***************************************************************************************************

erase "tmp/patriot.dta"
erase "tmp/asn.dta"

rmdir "tmp/"

log close
exit

